package templates

import java.awt.Color
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.widgets.TextBox
import org.uqbar.lacar.ui.model.Action

class EdicionAtributos {
	
	/** Crea una lista que tiene un boton para eliminar elementos de esta. */
	def listaEliminable(Panel p,String caption, String propertyLista,String propertyDel, Action eliminar){
		new Label(p) => [
			setText(caption)
			setBackground(Color :: LIGHT_GRAY)
			setWidth(280)
		]
		
		new List(p) => [
			bindItemsToProperty(propertyLista)
			bindValueToProperty(propertyDel)
			setHeight(35)
		]	
		
		val panelHorizontalEliminar = new Panel(p).setLayout(new HorizontalLayout)
		
		new Button(panelHorizontalEliminar) => [
			setCaption("Eliminar")
			setBackground(Color ::LIGHT_GRAY)
			setWidth(90)
			onClick(eliminar)
		]		
	}
	
	/** Crea un textBox con un boton para agregar y un boton aceptar */
	def agregarAtributoTBox(Panel p, String propertyAdd, Action add, Action closeAction){
		
		val panelHorizontalAgregar = new Panel(p).setLayout(new HorizontalLayout)
		
		 new TextBox(panelHorizontalAgregar) => [
			setWidth(200)
			bindValueToProperty(propertyAdd)
		]
		
		new Button(panelHorizontalAgregar) => [
			setCaption("Agregar")
			setBackground(Color ::LIGHT_GRAY)
			setWidth(90)
			onClick(add)/*Debería borrarse el textBox */
		]
		
		val panelHorizontalAceptar = new Panel(p).setLayout(new HorizontalLayout)
		
		new Button(panelHorizontalAceptar) => [
			setCaption("Aceptar")
			setBackground(Color ::LIGHT_GRAY)
			setWidth(90)
			onClick(closeAction)
		]
	}
	
	/** Crea un selector, con un boton de agregar y uno de aceptar */
	def agregarAtributoSel(Panel p, String listBind, String valueAdd, Action add, Action closeAction){
		
		val panelHorizontalAgregar = new Panel(p).setLayout(new HorizontalLayout)
		
		new Selector(panelHorizontalAgregar) => [
			allowNull(false)
			bindItemsToProperty(listBind)
			bindValueToProperty(valueAdd)
			setWidth(200)
		]
		
		new Button(panelHorizontalAgregar) => [
			setCaption("Agregar")
			setBackground(Color ::LIGHT_GRAY)
			setWidth(90)
			onClick(add)
		]
		
		val panelHorizontalAceptar = new Panel(p).setLayout(new HorizontalLayout)
		
		new Button(panelHorizontalAceptar) => [
			setCaption("Aceptar")
			setBackground(Color ::LIGHT_GRAY)
			setWidth(90)
			onClick(closeAction)
		]
	}	
}